package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by archoud on 3/5/14.
 */
public class Library {
    private UserIO userIO;
    private List<Book> books = new ArrayList<Book>();
    private List<String> menuOptions = new ArrayList<String>();

    public Library(UserIO userIO) {
        this.userIO = userIO;
        setupBooks();
        setupMenu();
    }

    private void setupMenu() {
        menuOptions.add("Display books");
    }

    private void setupBooks() {
        books.add(new Book("Head First Java"));
        books.add(new Book("Refactoring"));
        books.add(new Book("TDD By Example"));
    }

    public void greet() {
        userIO.print("Welcome to Biblioteca");
    }

    public void printBooks() {
        String header = "Books:";
        String bookList = new Displayer().format(header, books);
        userIO.print(bookList);
    }

    public void displayMenu() {
        String header = "Main Menu:";
        String menu = new Displayer().format(header, menuOptions);
        userIO.print(menu);
    }

    public void getMenuChoice() {
        String choice = userIO.getInput();
    }

    public boolean checkInput(String userInput) {

        boolean result;

        if (!isInteger(userInput)) {
            result = false;
        } else {

            int intInput = Integer.parseInt(userInput);
            if (intInput > 0 && intInput <= menuOptions.size()) {
                result = true;
            } else {
                result = false;
            }
        }

        return result;
    }

    private boolean isInteger(String userInput) {

        try {
            Integer.parseInt(userInput);
            return true;
        } catch (NumberFormatException nfe) {
            return false;
        }

    }
}
